import time
import multiprocessing

def get_html(n):
    time.sleep(n)
    print("sub_progress success {}".format(n))
    return n

if __name__ == '__main__':
    # progress = multiprocessing.Process(target=get_html, args=(3,))
    # print(progress.pid)
    # print(progress.is_alive())
    # progress.start()
    # print(progress.pid)
    # print(progress.is_alive())
    # progress.join()
    # print(progress.is_alive())
    # print("main progress end")
    # print(multiprocessing.cpu_count())

    # 使用线程池
    pool = multiprocessing.Pool(multiprocessing.cpu_count())
    # result = pool.apply_async(get_html, args=(3,))
    #
    # # 等待所有任务完成
    # pool.close()
    # pool.join()
    # print(result.get())

    # imap
    # for result in pool.imap(get_html, [1, 5,3]):
    #     print("{} sleep success".format(result))
    #
    for result in pool.imap_unordered(get_html, [1, 5,3]):
        print("{} sleep success".format(result))

